package practice07;

public class Teacher extends Person{
    //再写一个Teacher类继承Person类，除了name，age属性，还有klass属性。也有一个introduce方法，
    //introduce方法返回一个字符串形如：
    //>My name is Tom. I am 21 years old. I am a Teacher. I teach Class 2.
    //如果klass为空，就会返回：
    //>My name is Tom. I am 21 years old. I am a Teacher. I teach No Class.
    //写一个introduceWith方法，传入一个student，比如Jerry，如果Jerry是Teacher教的班级则返回形如：
    //>My name is Tom. I am 21 years old. I am a Teacher. I teach Jerry.
    //否则返回：
    //>My name is Tom. I am 21 years old. I am a Teacher. I don't teach Jerry.
    private Klass klass;

    public Klass getKlass() {
        return klass;
    }

    public void setKlass(Klass klass) {
        this.klass = klass;
    }
    public Teacher(String name, Integer age) {
        super(name, age);
    }

    public Teacher(String name, Integer age, Klass klass) {
        super(name, age);
        this.klass = klass;
    }
    //写一个introduceWith方法，传入一个student，比如Jerry，如果Jerry是Teacher教的班级则返回形如：
    //>My name is Tom. I am 21 years old. I am a Teacher. I teach Jerry.
    //否则返回：
    //>My name is Tom. I am 21 years old. I am a Teacher. I don't teach Jerry.
    public String introduceWith(Student student) {
        Klass studentClass = student.getKlass();
        String words = String.format("My name is %s. I am %d years old. I am a Teacher.", this.getName(), this.getAge());
        words += studentClass.equals(this.klass) ? String.format(" I teach %s.", student.getName())
                : String.format(" I don't teach %s.", student.getName());
        return words;
    }
    //introduce方法返回一个字符串形如：
    //>My name is Tom. I am 21 years old. I am a Teacher. I teach Class 2.
    @Override
    public String introduce() {
        String words = super.introduce() + " I am a Teacher.";
        words += this.klass != null ? " I teach Class "+this.klass.getNumber()+"." : " I teach No Class.";
        return words;
    }
}
